import React, { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

function WhileRouter({children}) {
    function NewCap(){
        const navigate=useNavigate()
        const {pathName}=useLocation()
        const token=localStorage.getItem("token")
        const WhileList=['/','login']

        useEffect(()=>{
            if(!token && !WhileList.includes[pathName]){
                navigate("/login")
            }
        },[])
        return children 
    }
  return <NewCap></NewCap>
}

export default WhileRouter
